<template>
    <div>
        <header class="pr white" style="padding: 45px 0px 40px;">
            <img src="../../assets/images/7.jpg" class="displayB centerauto shadowB" style="max-width: 70%;margin: 0px auto;padding: 10px;background: #fff;" />
        </header>
        <div v-for="(item,index) in list" :key="index" class="van-cell flexbox spacebetween">
            <div>
                <div>
                    <span>{{item.p_name}}</span>
                    <img :src="item.p_photo" height="20" style="vertical-align: middle;" />
                </div>
                <div class="flexbox spacebetween">
                    <p>市值：{{item.us_securities_money}}</p>
                    <p class="margin_l30">昨日收益：{{item.us_yesterday_earnings}}</p>
                </div>
            </div>
            <van-button type="primary" size="small" @click="cashFun(item.us_id)">提现到余额</van-button>
        </div>

        <!-- 提现额度 -->
        <van-dialog v-model="show" title="提现到余额" show-cancel-button @confirm="onconfirm">
            <van-field v-model="money" type="number" label="提现金额：" placeholder="请输入提现金额" style="margin: 15px 0;" />
        </van-dialog>
    </div>
</template>
<script>

    import '@/assets/css/main.css'
    export default {
        data(){
            return{
                list: [],
                money: '',
                show: false,
                usid: '',
            }
        },
        methods: {
            init(){
                var _this = this;

                this.$httpGet('/api/index/Personal_center/getHaveProjectList',{
                    'u_id': window.localStorage.u_id,
                }).then(response => {
                    
                    if(response.code == 200){

                        _this.list = response.msg;
                    }else{
                        
                        _this.$toast(response.msg);
                    }

                });
            },
            //提现
            submit(){

                var _this = this;

                this.$httpPost('/api/index/Personal_center/securitiesToMoney',{
                    'u_id': window.localStorage.u_id,
                    'us_id': this.usid,
                    'money': this.money,
                }).then(response => {
                    
                    if(response.code == 200){

                        _this.$toast(response.msg);
                        _this.init();

                    }else{
                        
                        _this.$toast(response.msg);
                    }

                });
            },
            //提现到余额
            cashFun(usid){
                // console.log(usid);
                this.usid = usid;
                this.show = true;
            },
            //确认
            onconfirm(){
                if(!this.money){
                    this.$toast('请输入提现金额');
                }else{

                    if(parseFloat(this.money)%100 != 0){
                         this.$toast('提现金额需是100的倍数');
                        return;
                    }

                    this.submit();
                }
            },
        },
        mounted(){
            this.init();
        },
    }
</script>